Improve xm vcpu-list command for inactive managed domains.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 19 Jul 2007 16:17:25 +0000 (17:17 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 19 Jul 2007 16:17:25 +0000 (17:17 +0100)
Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/main.py

index 94a02049a6f2a141687a4e805b846e5e82deae92..eb5c57556cff6c11b0bdc254c2d8de562f7b7da5 100644 (file)
@@ -632,16 +632,27 @@ class XendDomainInfo:
                     ['vcpu_count', self.info['VCPUs_max']]]
 
             for i in range(0, self.info['VCPUs_max']):
-                info = xc.vcpu_getinfo(self.domid, i)
-
-                sxpr.append(['vcpu',
-                             ['number',   i],
-                             ['online',   info['online']],
-                             ['blocked',  info['blocked']],
-                             ['running',  info['running']],
-                             ['cpu_time', info['cpu_time'] / 1e9],
-                             ['cpu',      info['cpu']],
-                             ['cpumap',   info['cpumap']]])
+                if self.domid is not None:
+                    info = xc.vcpu_getinfo(self.domid, i)
+
+                    sxpr.append(['vcpu',
+                                 ['number',   i],
+                                 ['online',   info['online']],
+                                 ['blocked',  info['blocked']],
+                                 ['running',  info['running']],
+                                 ['cpu_time', info['cpu_time'] / 1e9],
+                                 ['cpu',      info['cpu']],
+                                 ['cpumap',   info['cpumap']]])
+                else:
+                    sxpr.append(['vcpu',
+                                 ['number',   i],
+                                 ['online',   0],
+                                 ['blocked',  0],
+                                 ['running',  0],
+                                 ['cpu_time', 0.0],
+                                 ['cpu',      -1],
+                                 ['cpumap',   self.info['cpus'] and \
+                                              self.info['cpus'] or range(64)]])
 
             return sxpr
 
index e58b1418eb981d29c19907f9afd0b6e75ac1e3b6..9bd95605c72baed8de02e1b52bdf5725f371541d 100644 (file)
@@ -1023,13 +1023,13 @@ def xm_vcpu_list(args):
         if args:
             dominfo = map(server.xend.domain.getVCPUInfo, args)
         else:
-            doms = server.xend.domains(False)
+            doms = server.xend.domains_with_state(False, 'all', False)
             dominfo = map(server.xend.domain.getVCPUInfo, doms)
 
     print '%-32s %5s %5s %5s %5s %9s %s' % \
           ('Name', 'ID', 'VCPU', 'CPU', 'State', 'Time(s)', 'CPU Affinity')
 
-    format = '%(name)-32s %(domid)5d %(number)5d %(c)5s %(s)5s ' \
+    format = '%(name)-32s %(domid)5s %(number)5d %(c)5s %(s)5s ' \
              ' %(cpu_time)8.1f %(cpumap)s'
 
     for dom in dominfo:
@@ -1098,8 +1098,12 @@ def xm_vcpu_list(args):
 
             return format_pairs(list_to_rangepairs(cpumap))
 
-        name  =     get_info('name')
-        domid = int(get_info('domid'))
+        name  = get_info('name')
+        domid = get_info('domid')
+        if domid is not None:
+            domid = str(domid)
+        else:
+            domid = ''
 
         for vcpu in sxp.children(dom, 'vcpu'):
             def vinfo(n, t):
@@ -1113,7 +1117,10 @@ def xm_vcpu_list(args):
             running  = vinfo('running',  int)
             blocked  = vinfo('blocked',  int)
 
-            if online:
+            if cpu < 0:
+                c = ''
+                s = ''
+            elif online:
                 c = str(cpu)
                 if running:
                     s = 'r'
@@ -1125,8 +1132,8 @@ def xm_vcpu_list(args):
                     s += '-'
                 s += '-'
             else:
-                c = "-"
-                s = "--p"
+                c = '-'
+                s = '--p'
 
             print format % locals()